package com.sun.wms.controller;

import com.sun.wms.common.Result;
import com.sun.wms.entity.User;
import com.sun.wms.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/user")
public class UserController {
    @Autowired
    private UserService userService;

    @PostMapping("/query")
    public Result queryUsers(@RequestBody User user) {
        List<User> users = userService.queryUsers(user);
        Result result = new Result();
        if (users.size() > 0) {
            return Result.suc(users, (long) users.size());
        }else {
          return Result.fail();

        }


    }
    @PostMapping("/updata")
    public Result updataUsers(@RequestBody User user) {
        int success = userService.updateUser(user);
        if (success>0) {
            return Result.suc("用户信息修改成功");
        } else {
            return Result.fail();
        }


    }
    @PostMapping("/deleteUsersBatch")
    public Result deleteUsers(@RequestBody List<Long> ids) {
        int success = userService.deleteUsersBatch(ids);
        if (success>0) {
            return Result.suc("用户批量删除成功");
        } else {
            return Result.fail();
        }


    }
    @PostMapping("/addUsersBatch")
    public Result addUsers(@RequestBody List<User> userList) {
       boolean success = userService.addUsersBatch(userList);
        if (success) {
            return Result.suc("用户批量添加成功");
        } else {
            return Result.fail();
        }


    }


}
